<?php
/**
 * @file pushmessage.php $
 * @author LiangJian (liangjian@haibao.com) $
 * @date 2015年9月1日 下午12:45:07 $
 * @brief 推送消息 $
 */
namespace haibao\app\data;

use \haibao\frame\data\query\Condition;

class PushMessage extends \haibao\app\data\BaseMysql{

    public function __construct(){
        parent::__construct('\haibao\app\model\data\PushMessage');
    }

    public function getPushMessageById($id){
        return $this->getOneById($id);
    }
    
    public function updateStatusById($id, $status = \haibao\app\model\data\PushMessage::STATUS_DISABLE){
        $this->updateById($id, array(
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_STATUS => $status,
        ));
    }
    
    /**
     * @param \haibao\app\model\data\PushMessage $model
     */
    public function addPushMessage($model){
        $this->add($model);
    }
    
    /**
     * @param \haibao\app\model\data\PushMessage $model
     */
    public function updatePushMessage($model){
        if(!$model->Id){
            return false;
        }
        $this->updateById($model->Id, array(
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_PUSH_OBJECT => $model->PushObject,
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_TITLE => $model->Title,
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_CONTENT => $model->Content,
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_ARTICLE_ID => $model->ArticleId,
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_PUBLISHED => $model->Published,
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_PUBLISH_TIME => $model->PublishTime,
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_SEND_TIME_TYPE => $model->SendTimeType,
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_USER_RANGE => $model->UserRange,
        ));
    }
    
    public function updatePublishedById($id, $published = \haibao\app\model\data\PushMessage::PUBLISHED_YES){
        if(!$id) return false;
        $this->updateById($id, array(
            \haibao\app\model\filter\PushMessage::CONDITION_FIELD_NAME_PUBLISHED => $published,
        ));
    }
}